package wy;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/12/2215:57
 */
@Component
@Slf4j
public class MyFilter extends ZuulFilter{
    //过滤器类型：pre前置过滤器 routing：路由之时       post： 路由之后      error：发送错误调用
    @Override
    public String filterType() {
        return "pre";
    }
    //过滤器一般可以有多个 0最先执行；数字越大，执行越靠后
    @Override
    public int filterOrder() {
        return 0;
    }
    //过滤器的开关
    @Override
    public boolean shouldFilter() {
        return true;
    }
    //过滤器的核心方法体
    @Override
    public Object run() throws ZuulException {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        log.info(String.format("%s >>> %s", request.getMethod(), request.getRequestURL().toString()));
        return null;
    }
}
